<template>
  <div>
    <div class="header">
      <van-image
        width="60"
        height="60"
        fit="cover"
        round
        :src="userInfo.photo"
      />
      <h4>
        {{ userInfo.name }}
        <br />
        <van-tag color="#fff" text-color="#009afb">{{
          userInfo.birthday
        }}</van-tag>
      </h4>
    </div>
    <van-row class="user-nav">
      <van-col span="8">
        <van-icon name="newspaper-o" color="#7af" />
        <span>我的作品</span>
      </van-col>
      <van-col span="8">
        <van-icon name="star-o" color="#f00" />
        <span>我的收藏</span>
      </van-col>
      <van-col span="8">
        <van-icon name="tosend" color="#fa0" />
        <span>阅读历史</span>
      </van-col>
    </van-row>
    <van-cell-group>
      <van-cell title="编辑资料" icon="edit" is-link @click="$router.push('/edit')"/>
      <van-cell title="小智同学" icon="chat-o" is-link @click="$router.push('/student')"/>
      <van-cell title="系统设置" icon="setting-o" is-link />
      <van-cell title="退出登录" icon="warning-o" is-link @click="logOut" />
    </van-cell-group>
  </div>
</template>

<script>
import { getUserInfo } from './user.js'
import {removeToken} from '@/utils/token.js'
export default {
  name: 'user',
  data() {
    return {
      userInfo: {},
    }
  },
  created () {
    getUserInfo().then(res => {
      console.log(res)
      this.userInfo = res.data.data
      this.$store.commit('updateUserInfo',res.data.data)
    })
  },
  methods: {
    logOut () {
      this.$dialog.confirm({
        title: '提示',
        message: '确认要退出登录吗？'
      })
        .then(() => {
          removeToken()
          this.$router.push('/login')
        })
    }
  }
}
</script>

<style lang="less">
.header {
  height: 100px;
  background-color: #009afb;
  display: flex;
  align-items: center;
  .van-image {
    padding: 0px 15px;
  }
  h4 {
    font-size: 18px;
    font-weight: 400;
    color: #fff;
  }
}
.user-nav {
  .van-col {
    margin: 10px 0;
    text-align: center;
  }
  span {
    display: block;
    font-size: 12px;
  }
}
</style>
